using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;
using Facebook.Service.Core;
using Facebook;
using System.Collections.ObjectModel;

namespace Profile
{
    [Serializable]
    public class CBuddyIdAssociation: Dictionary<string,string>//IDictionary<string,string>
    {
        private Facebook.Components.FacebookService m_service;
        public CBuddyIdAssociation(Facebook.Components.FacebookService sr)
        {
            m_service = sr;
        }

        /// <summary>
        /// Associates a screen name with a full name. The full
        /// name will be resolved into a facebook userId and stored in 
        /// a hash.
        /// </summary>
        /// <param name="screenName"></param>
        /// <param name="nm">Full name that is associated with
        /// the facebook account
        /// </param>
        /// <param name="d">needed a different signature</param>
        public new void Add(string screenName, string nm)
        {
            string id = findFaceboookId(nm);
            base.Add(screenName, id);
        }

        private string findFaceboookId(string nm)
        {
            Collection<User> friends = m_service.GetFriends();
            foreach (User fr in friends)
            {
                if (fr.Name == nm) return fr.UserId;
            }
            return null;
        }

    }
}
